function mask = guigetmask(structure)

%
%    mask = guigetmasks(structure)
%
%    Get masks semi-automatically from the elastic scan STRUCTURE
%    (read with MAXISTRUCT). The function asks user to set the 
%    threshold level with GUI tool. Output is a NMASKSx256x256 
%    uint8-matrix, compatible with MAXISERIES.
%


img = zeros(size(structure(1).frame),'int16');	%get detector image
for i = 1 : length(structure)
	img = img + structure(i).frame;
end

img = double(img);

thres = guigetthreshold(img);
display(sprintf('Threshold level set to %f',thres));
masks=autodetectroi(img,5,thres); %find masks

try
	masks;
	mask=roi_lin2mat(masks);
catch,warning('The mask list is empty!');
end

end
 
